﻿using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SmartPhone.Un.Pro.FileManagement
{
    /// <summary>
    /// LogUtility의 요약 설명입니다.
    /// </summary>
    public class LogUtility
    {
        public LogUtility()
        {

        }

        /// <summary>
        /// Log error message to log file
        /// </summary>
        /// <param name="ex"></param>
        public static void LogMessage(string message)
        {
            System.IO.StreamWriter sw = null;
            try
            {
                string logDir = HttpContext.Current.Server.MapPath("~") + "\\Log";
                if (!Directory.Exists(logDir))
                {
                    Directory.CreateDirectory(logDir);
                }
                string logFile = logDir + string.Format("\\{0:yyyyMMdd}.log", DateTime.Today);
                if (!System.IO.File.Exists(logFile))
                    System.IO.File.Create(logFile).Close();
                sw = new System.IO.StreamWriter(logFile, true);
                sw.WriteLine(string.Format("[{0:yyyy-MM-dd HH:mm:ss} {1}] ", DateTime.Now, message));
                sw.Flush();
            }
            catch
            {
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }

            }
        }
    }

}